﻿@model IEnumerable<ProductManage_WCG.Models.ProInfo>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>

</p>
<form action="/" method="get" class="form-inline text-center " style="margin:15px">
    物资类型：@Html.DropDownList("Type", null, new { @class = "form-control" })
    物资名称：<input type="text" name="Name" placeholder="请输入物资名称" class="form-control" />
    <input type="submit" value="查询" class="btn btn-primary " />
    <a href="@Url.Content("~/Home/Create")" class="btn btn-primary ">添加物资</a>
</form>
<table class="table">

    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTimeStr)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IsDestroy)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Unit)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ProType.Name)
        </th>
        <th>操作</th>
    </tr>
    @{
        if (ViewBag.Tips == "T")
        {
            <tr><td colspan="9">不好意思啊，未找到相关信息</td></tr>        }
        else
        {

            foreach (var item in Model)
            {

                <tr>
                    <td>

                        @Html.DisplayFor(modelItem => item.ID)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.AddTimeStr)
                    </td>
                    <td data-edit="@item.ID">
                        @{
                            string str = item.IsDestroy.ToString() == "False" ? "未报废" : "已报废";
                        }

                        @Html.DisplayFor(modelItem => str)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Unit)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Price)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Description)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ProType.Name)
                    </td>

                    @if (!item.IsDestroy)
                    {
                        <td>
                            <a href="#" data-edit="@item.ID">报废</a>
                        </td>
                    }

                </tr>
            }
        }
    }
</table>
@section Scripts {

    <script type="text/javascript">
        $(function () {
            $("a[data-edit]").click(function () {
                var $this=$(this)
                var id = $(this).attr("data-edit")
                if (!confirm("确定要报废编号为" + id + "的物资？")) {
                    return;
                }
                $.post("@Url.Content("~/Home/Edit")", { id: id }, function (res) {
                    if (res) {
                        //刷新
                        $("td[data-edit='" + id + "']").text("测试报废");
                        $this.text(" ");
                        //location.reload();
                        alert("报废成功");
                    }
                })
            })
        })
    </script>


}
